<?php
/* SVN FILE: $Id: tp_market_number.php 212 2009-09-09 21:42:52Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Template Pluging: Format Number by ibMarket
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 212 $
* @lastrevision $Date: 2009-09-09 21:42:52 +0000 (Wed, 09 Sep 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-09-09 21:42:52 +0000 (Wed, 09 Sep 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/sources/template_plugins/tp_market_number.php $
*/

/**
* Main loader class
*/
class tp_market_number extends output implements interfaceTemplatePlugins
{
	/**
	 * Prevent our main destructor being called by this class
	 *
	 * @access	public
	 * @return	void
	 */
	public function __destruct()
	{
	}
	
	/**
	 * Run the plug-in
	 *
	 * @access	public
	 * @param	string	The initial data from the tag
	 * @param	array	Array of options [N/A]
	 * @return	string	Processed HTML
	 */
	public function runPlugin( $data, $options )
	{
		$options['decimal'] = $options['decimal'] ? intval($options['decimal']) : 0;
		$options['minimal'] = isset($options['minimal']) ? ($options['minimal'] ? 'true' : 'false') : 'true';
		switch($options['type'])
		{
			case 'stock':
				return '" . (numbers::compare('.$data.') < 0 ? "<em>".$this->lang->words[\'infinite\']."</em>" : marketFormatter::numberFormat('.$data.')) . "';
			case 'lasts':
				return '" . (numbers::compare('.$data.') <= 0 ? "<em>".$this->lang->words[\'forever\']."</em>" : marketFormatter::relativeTimeFull('.$data.')) . "';
			case 'expires':
				return '" . (numbers::compare('.$data.') <= 0 ? "<em>".$this->lang->words[\'never\']."</em>" : $this->registry->getClass(\'class_localization\')->getDate('.$data.', "SHORT" )) . "';
			case 'restock':
				return '" . (numbers::compare('.$data.') == 0 ? "<em>".$this->lang->words[\'never\']."</em>" : (numbers::compare('.$data.',IPS_UNIX_TIME_NOW) < 0 ? "<em>".$this->lang->words[\'now\']."</em>" : $this->registry->getClass(\'class_localization\')->getDate('.$data.', "TINY" ))) . "';
			case 'tax':
				return '" . (numbers::compare('.$data.') == 0 ? "<em>".$this->lang->words[\'no_tax\']."</em>" : marketFormatter::numberFormat('.$data.','.$options['decimal'].','.$options['minimal'].')."%") . "';
			case 'number':
			default:
				return '" . marketFormatter::numberFormat('.$data.','.$options['decimal'].','.$options['minimal'].') . "';
		}
	}
	
	/**
	 * Return information about this modifier
	 *
	 * It MUST contain an array  of available options in 'options'. If there are no allowed options, then use an empty array.
	 * Failure to keep this up to date will most likely break your template tag.
	 *
	 * @access	public
	 * @return   array
	 */
	public function getPluginInfo()
	{
		//-----------------------------------------
		// Return the data, it's that simple...
		//-----------------------------------------
		
		return array( 'name'    => 'format_number',
					  'author'  => 'supersmashbrothers',
					  'usage'   => '{parse market_number="123456"}',
					  'options' => array('type','decimal','minimal') );
	}
}